//
//  AVVideoComposition+x.m
//  XPhoto
//
//  Created by baboy on 2020/7/13.
//  Copyright © 2020 baboy. All rights reserved.
//

#import "AVVideoComposition+x.h"
#import "PhotoAsset.h"

@implementation AVVideoComposition(x)
+ (AVVideoComposition *)videoCompositionWithAsset:(AVAsset *)asset filter:(CIFilter *)filter{
//    AVAssetTrack *videoAssetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    UIInterfaceOrientation videoOrientation = AVAssetOrientation(asset);
    AVVideoComposition *composition = [AVVideoComposition videoCompositionWithAsset:asset applyingCIFiltersWithHandler:^(AVAsynchronousCIImageFilteringRequest * _Nonnull request) {
        //NSLog(@"导出中");//针对每一帧的图像做滤镜处理
        CIImage *sourceImage = [request.sourceImage imageByApplyingCGOrientation:kCGImagePropertyOrientationUp];
        [filter setValue:sourceImage forKey:kCIInputImageKey];
        CIImage *resultImage = filter.outputImage?:sourceImage;
        resultImage = [resultImage imageByCroppingToRect:request.sourceImage.extent];
        [request finishWithImage:resultImage context:nil];
    }];
    return composition;
}
@end
